#!/usr/bin/python3
# -*- encoding: utf-8 -*-
'''
@File    :   shangke.py
@Time    :   2020/08/18 21:32:33
@Author  :   Qing Bei
@Version :   1.0
@Contact :   1013575196@qq.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@Desc    :   
            验证回文   只验证数字字母  字母不区分大小写
'''

# here put the import lib


# 方法一 正则 + 切片
def func1(theInputStr: str) -> bool:
    # 单字符 或 空字符
    if len(theInputStr) == 0 or len(theInputStr) == 1:
        return False
    # 多字符
    else:
        import re
        tmpStr = re.sub('[^\w]','',theInputStr).upper()
        return True if tmpStr[:] == tmpStr[::-1] else False

# 方法二 数组和上面类似基本没变
def func2(theInputStr: str) -> bool:
    if len(theInputStr)==0 or len(theInputStr)==1:
        return False
    else:
        h_lst = []
        theInputStr = theInputStr.upper()
        for i in theInputStr:
            if i.isdigit() or i.isalpha():
                h_lst.append(i)
        tmp_lst = h_lst[:]
        h_lst.reverse()
        return True if h_lst == tmp_lst else False
    
# 方法三 传统双指针
def func3(theInputStr: str) ->bool:
    theInputStr = theInputStr.upper()
    i, j = 0, len(theInputStr)-1
    flag = True
    while i <= j:
        if theInputStr[i].isdigit() or theInputStr[i].isalpha():
            
            if theInputStr[j].isdigit() or theInputStr[j].isalpha() :
            
                if theInputStr[i] == theInputStr[j] :
                    if j>i:
                        i += 1
                        j -= 1
                    else:
                        return flag
                else:
                    flag=False
                    return flag
            else:
                j -= 1
        else:
            i += 1
    return flag
    
def main():
    user_input = input("请输入字符串用于验证数字字母回文验证")
    # print( func1(user_input) )
    # print( func2(user_input) )
    # print( func3(user_input) )
    
if __name__ == "__main__":
    main()